/*
 * @Author: ZhanXie
 * @Date: 2020-09-06 15:40:51
 * @LastEditors: ZhanXie
 * @LastEditTime: 2020-09-06 15:58:20
 * @Description: 广场 api 路由
 * @FilePath: /weibo/src/routes/api/blog-square.js
 */
const router = require('koa-router')()
const { loginCheck } = require('../../middlewares/loginChecks')
const { getSquareBlogList } = require('../../controller/blog-square')
const { getBlogListStr } = require('../../utils/blog')

router.prefix('/api/square')

router.get('/loadMore/:pageIndex', loginCheck, async (ctx, next) => {
  let { pageIndex } = ctx.params
  pageIndex = parseInt(pageIndex) // 转换 number 类型
  const result = await getSquareBlogList(pageIndex)
  // 渲染模板
  result.data.blogListTpl = getBlogListStr(result.data.blogList)

  ctx.body = result
})


module.exports = router